import redis from 'redis'
import elementUI from 'element-ui'
import bluebird from 'bluebird'
bluebird.promisifyAll(redis)

export default{
  createConnection (port, host, auth) {
    const options = {
      connect_timeout: 2000,
      retry_strategy: (options) => { return this.retryStragety(options) },
      no_ready_check: true,
      password: auth
    }
    return redis.createClient(port, host, options)
  },
  retryStragety (options) {
    if (options.times_connected >= 3) {
      elementUI.Message({
        type: 'error',
        message: window.$Vue.$t('RedisOperating.connectionError')
      })
      return false;
    }
    return Math.max(options.attempt * 100, 1000)
  }
}
